import { useLocalStorage } from '@vueuse/core';

const KEY = 'TOKEN';

/**
 * 设置token和获取token
 * @returns
 */
export const useToken = () => {
  const tokenStorage = useLocalStorage(KEY, '');

  // 获取token
  const getToken = () => tokenStorage.value;

  // 设置token
  const setToken = (_token: string) => (tokenStorage.value = _token);

  const clearToken = () => (tokenStorage.value = '');

  return { setToken, getToken, clearToken };
};
